﻿
Imports osi.root.constants

Public Module _assert
    Public Sub assert_break()
        If isdebugmode() AndAlso Not strongassert() Then
            attach_debugger()
        Else
            suicide()
        End If
    End Sub

    Private Function assert_failed(ByVal msg() As Object) As Boolean
        k_raise_error(If(isemptyarray(msg), "assert failed.", "assert failed, "),
                      msg,
                      newline.incode(),
                      callstack())
        assert_break()
        Return False
    End Function

    Public Function k_assert(ByVal v As Boolean) As Boolean
        Return v OrElse assert_failed(Nothing)
    End Function

    Public Function k_assert(ByVal v As Boolean, ByVal ParamArray msg() As Object) As Boolean
        Return v OrElse assert_failed(msg)
    End Function

    'the debug_k_assert definition is not the same as debug_assert, it will not assert in debug mode and return true
    Public Function debug_k_assert(ByVal v As Boolean) As Boolean
        Return debug_k_assert(isdebugmode() OrElse v)
    End Function

    Public Function debug_k_assert(ByVal v As Boolean, ByVal ParamArray msg() As Object) As Boolean
        Return k_assert(isdebugmode() OrElse v, msg)
    End Function
End Module
